#!/usr/bin/perl
# vim: set cindent expandtab ts=4 sw=4:
#
# abook_tpl.pl - a simple script to generate rich_abook.inc, this will
#                developer focus on coding instead of boring html code
#                typing :-)
#
# Author: hzqbbc hzqbbc@hzqbbc.com
#   Date: 22:34:00 2008-03-15
#    VER: 0.1
# $Id$

# CSV header, but split into 4 chunks, map to 4 tabs in UI
@h = (['Name','Email','NickName','Mobile', 'Job', 'IMgoogle','IMmsn','IMqq','IMskype'],
      ['HomeTel','HomeAddress','HomeCity','HomeState','HomeZip','HomeCountry'],
      ['Company','WorkMail','WorkTel','WorkFax','WorkAddress','WorkCity','WorkState','WorkZip','WorkCountry'],
      ['OtherMail','OtherPhone','WebSite','BirthDay','IMaol','IMicq','Notes', 'Picture'],
);

my $build_type = $ARGV[0];

die "$0 (html|lang|all)\n" unless $build_type;

if ($build_type eq 'html') {
    build_html();
} elsif ($build_type eq 'lang') {
    build_lang();
} else {
    build_html();
    build_lang();
}

sub build_html {
    my $i = 1;
    print "<!-- This part is auto generated by hzqbbc's stupid script :) -->\n";
    for my $p (@h) {
	    print "<div id=\"Content$i\" class=\"content\"";
	    if ($i!=1) {
		    print ' style="display: none"';
	    }
	    print ">\n";
	    print '<table cellpadding=5 cellspacing=5 class="content-tab">'."\n";
	    for my $m (@$p) {
		    my $name = lc $m;
		    my $val = uc $m;
		    print "\t<tr>\n".
		      "\t\t<td class=abkey><\%ab_$name%></td><td><input name=\"ab_$name\" value=\"<\%AB_$val%>\"></td>\n".
		      "\t</tr>\n";
	    }
	    print "</table>\n";
	    print "</div>\n";
	    $i++;
    }
    print "<!-- This is the end of rich_abook.inc -->\n";
}

sub build_lang {
    for my $p (@h) {
	    for my $m (@$p) {
		    my $name = lc $m;
		    print "    ab_$name => '',\n";
	    }
    }
}
